collections {
   group { name: "main";
      script {
         public g_duration = 0, g_stopslide, g_timer_id, g_anim_id, toggle=0;

         public slide_to_end_anim(val, Float:pos) {
            new stopflag;
            new id;
            new Float:duration;
            stopflag = get_int(g_stopslide);
            duration = get_float(g_duration);
            if (stopflag == 1) return;
            set_tween_state_anim(PART:"move","slide_end", 0.0, "slide_begin", 0.0, ACCEL , pos);
            if (pos >= 1.0) {
               id = anim(duration, "slide_to_start_anim", 1);
               set_int(g_timer_id, id);
            }
         }
         public slide_to_start_anim(val, Float:pos) {
            new stopflag;
            new id;
            new Float:duration;
            stopflag = get_int(g_stopslide);
            duration = get_float(g_duration);
            if (stopflag == 1) return;
            set_tween_state_anim(PART:"move","slide_begin", 0.0, "slide_end", 0.0, DECEL , pos); 
            if (pos >= 1.0) {
               id = anim(duration, "slide_to_end_anim", 1);
               set_int(g_timer_id, id);
            }
         }
         public slide_to_end() {
            new stopflag;
            new id;
            new Float:duration;
            stopflag = get_int(g_stopslide);
            if (stopflag == 1) return;
            duration = get_float(g_duration);
            id = anim(duration, "slide_to_end_anim", 1);
            set_int(g_anim_id, id);
         }
         public slide_to_begin() {
            new stopflag;
            new id;
            stopflag = get_int(g_stopslide);
            if (stopflag == 1) return;
            set_state(PART:"move", "slide_begin", 0.0);
            id = timer(0.5, "slide_to_end", 1);
            set_int(g_timer_id, id);
         }
         public start_slide() {
            set_int(g_stopslide, 0);
            set_float(g_duration, 1.3);
            set_state(PART:"move", "slide_begin", 0.0);
            slide_to_end();
         }
         public stop_slide() {
            new id;
            set_int(g_stopslide, 1);
            id = get_int(g_anim_id);
            cancel_anim(id);
            id = get_int(g_timer_id);
            cancel_timer(id);
            set_state(PART:"move", "default", 0.0);
         }
      }
      parts {
         part { name: "bg";
            type: RECT;
            description { state: "default" 0.0;
               color: 255 255 255 255;
            }
         }
         part { name: "label";
            type: TEXT;
            description { state: "default" 0.0;
               color: 255 0 0 255;
               text {
                  text: "Click me.";
                  font: "Sans";
                  size: 12;
                  align: 0.5 0.8;
               }
            }
         }
         part { name: "rect1";
            type: RECT;
            description { state: "default" 0.0;
               color: 255 0 0 255;
               min: 30 30;
               max: 30 30;
               fixed: 1 1;
               align: 0.1 0.2;
            }
         }
         part { name: "rect2";
            type: RECT;
            description { state: "default" 0.0;
               color: 0 255 0 255;
               min: 30 30;
               max: 30 30;
               fixed: 1 1;
               align: 0.9 0.2;
            }
         }
         part { name: "rect";
            type: RECT;
            description { state: "default" 0.0;
               rel1 {
                  to: "rect1";
                  relative: 1.0 0.0;
               }
               rel2 {
                  to:"rect2";
                  relative: 0.0 1.0;
               }
            }
         }
         part {
            name: "move";
            type: RECT;
            description {
               state: "default" 0.0;
               align: 0.0 0.0;
               min: 30 30;
               max: 30 30;
               fixed: 1 1;
               color: 0 0 255 255;
               rel1 {
                  to: "rect1";
                  relative: 1.0 0.0;
               }
               rel2 {
                  to:"rect1";
                  relative: 1.0 1.0;
               }
            }
            description {
               state: "slide_end" 0.0;
               inherit: "default" 0.0;
            }
            description {state: "slide_begin" 0.0;
               inherit: "default" 0.0;
               align: 1.0 1.0;
               rel1 {
                  to: "rect2";
                  relative: 0.0 0.0;
               }
               rel2 {
                  to:"rect2";
                  relative: 0.0 1.0;
               }
            }
         }
      }
      programs {
         program {signal: "mouse,down,1";
            source: "label";
            script{
               start_slide();
            }
         }
         program { name: "go_left";
            script{
               stop_slide();
            }
         }
      }
 }
